#include "cppTutorSTLVector.h"

#include <iostream>

using namespace std;

CcppTutorSTLVector :: CcppTutorSTLVector () : m_nTakeUserChoice (0), m_nData (0), m_strDataType ("int"), m_bExitSignal(false)
{
}

CcppTutorSTLVector :: ~CcppTutorSTLVector ()
{
}

int CcppTutorSTLVector :: showMenu ()
{
    while (true)
    {
        cout << "------------------------------" << endl;
        cout << "1. create a vector" << endl;
        cout << "9. Exit" << endl;
        cout << "------------------------------" << endl;
        cin >> m_nTakeUserChoice;
        switch (m_nTakeUserChoice)
        {
            case 1:
                createVector ();
                m_bExitSignal = false;
                break;
                
            case 9:
                m_bExitSignal = true;
                break;
            default:
                cout << "Not a supported choice" << endl;
                break;
        }
        if (m_bExitSignal)
        {
            return 0;
        }
    };
}

int CcppTutorSTLVector :: createVector ()
{
    m_bExitSignal = false;
    while (m_bExitSignal == false)
    {
        cout << "\nEnter the data type of the Vector ?" << endl;
        cin >> m_strDataType;
    
        if (m_strDataType.compare ("int") == 0)
        {
            cout << "Creating vector of " << m_strDataType << endl;
            //m_bExitSignal = true; // exit with while loop for further operation

            int nSize = 0;
            cout << "How many element you want to enter\n" << endl;
            cin >> nSize;
            for (int i = 0; i < nSize; i++)
            {
                cout << "Enter the element : ";
                cin >> m_nData;
                vint.push_back (m_nData);
                m_nData = 0;
            }

            m_bExitSignal = false;
            while (m_bExitSignal == false)
            {
                cout << "Supported Opeartion on Vector\n" << endl;
                cout << "1. Display" << endl;
                cout << "2. Size " << endl;
                cout << "3. Capacity" << endl;
                cout << "4. Erase" << endl;
                cout << "9. Exit" << endl;
                cout << "\nEnter your choice" << endl;
                m_nTakeUserChoice = 0;
                cin >> m_nTakeUserChoice;
                switch (m_nTakeUserChoice)
                {
                    case 1:
                        for (vint_it = vint.begin (); vint_it !=vint.end (); ++vint_it)
                        {
                            cout << " " << *vint_it;
                        }
                        cout << endl;
                        break;

                    case 2:
                        cout << "size of the vector created is : " << vint.size ();
                        break;

                    case 3:
                        cout << "capacity of the vector created is : " << vint.capacity ();
                        break;

                    case 4:
                        cout << "enter the position of the element you want to delete " << endl;
                        m_nData = 0;
                        cin >> m_nData;
                        vint.erase (vint.begin () + (m_nData - 1));
                        break;

                    case 9:
                        m_bExitSignal = true;
                        cout << "Warning : Removing all the elements of the vector !!!" << endl;
                        vint.clear ();
                        break;

                    default:
                        cout << "Unsupported Choice" << endl;
                        break;
                }
            };
        }
        else
        {
            cout << endl << m_strDataType << " : data type Not implemented yet !!!" << endl;
        }
     };
/*
    int nSize;
    cout << "How many element you want to enter\n" << endl;
    cin >> nSize;
    for (int i = 0; i < nSize; i++)
    {
        cout << "Enter the element : ";
        cin >> m_nData;
        vint.push_back (m_nData);
        m_nData = 0;
    }

    m_bExitSignal = false;
    while (m_bExitSignal == false)
    {
        cout << "Supported Opeartion on Vector\n" << endl;
        cout << "1. Display" << endl;
        cout << "2. Size " << endl;
        cout << "3. Capacity" << endl;
        cout << "4. Erase" << endl;
        cout << "9. Exit" << endl;
        cout << "\nEnter your choice" << endl;
        m_nTakeUserChoice = 0;
        cin >> m_nTakeUserChoice;
        switch (m_nTakeUserChoice)
        {
            case 1:
                for (vint_it = vint.begin (); vint_it !=vint.end (); ++vint_it)
                {
                    cout << " " << *vint_it;
                }
                cout << endl;
                break;

            case 2:
                cout << "size of the vector created is : " << vint.size ();
                break;

            case 3:
                cout << "capacity of the vector created is : " << vint.capacity ();
                break;

            case 4:
                cout << "enter the position of the element you want to delete " << endl;
                m_nData = 0;
                cin >> m_nData;
                vint.erase (vint.begin () + (m_nData - 1));
                break;

            case 9:
                m_bExitSignal = true;
                break;

            default:
                cout << "Unsupported Choice" << endl;
                break;
        }
    };
*/
    return 0;
}
